<template>
  <div class="search_view">
    <control></control>
    <contents :datas="content"></contents>
  </div>
</template>

<script>
import Control from "components/private/search/Control";
import Contents from "components/private/search/Content";
import debounce from "tool/debounce";
export default {
  components: {
    Control,
    Contents
  },
  data() {
    return {
      content: null,
      timer: null
    };
  },
  methods: {
    request(keyword) {
      this.$axios({
        url: "/search",
        method: "get",
        params: {
          keyword
        }
      }).then(res => {
        console.log(res);
        this.content = res;
      });
    }
  },
  created() {
    
    
    this.$bus.$on("isNull", () => {
      this.content = null;
    });
    this.$bus.$on("input", keyword => {
      // 防抖
      clearTimeout(this.timer);
      this.timer = setTimeout(() => {
        this.request(keyword);
      }, 1000);
    });
  }
};
</script>

<style lang="less" scoped>
.search_view {
  background-color: #fff;
  padding-top: 45px;
}
</style>